package com.mapper;

import com.domain.Place_data;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.service.Public_funtion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class Place_mysql {

    //广告内容
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Resource
    private Public_funtion p;






        public List<Place_data> get_place_all()
        {
            List<Place_data> place_List= new ArrayList();
            Place_data mysql_list = new Place_data();
            String sql="select * FROM Place";
            List list = jdbcTemplate.queryForList(sql);
            if(list.size()>0)
            {
                for (int i=0 ; i<list.size();i++)
                {
                    Object MSO = list.get(i);
                    ObjectMapper objectMapper = new ObjectMapper();
                    mysql_list = objectMapper.convertValue(MSO, Place_data.class);
                    place_List.add(mysql_list);
                }

                return place_List;
            }
            else
            {
                System.out.println("mysql数据库中地址表中没有数据");
                return place_List;
            }
        }

    public List<Place_data> get_place(Place_data data)
    {

        String sql="select * FROM Place WHERE"+
                " id  LIKE '%'  "+
                p.sql_null_selsect("place_id",String.valueOf(data.getPlace_id()))+
                p.sql_null_selsect("box_id",String.valueOf(data.getBox_id()))+
                p.sql_null_selsect("box_type",String.valueOf(data.getBox_id()))+
                p.sql_null_selsect("place",data.getPlace())+
                p.sql_null_selsect("place_long",data.getPlace_long())+
                p.sql_null_selsect("type",data.getType())+
                p.sql_null_selsect("city",String.valueOf(data.getCity()))+
                p.sql_null_selsect("week",String.valueOf(data.getWeek()))+
                p.sql_null_selsect("day",String.valueOf(data.getDay()))+
                p.sql_null_selsect("mouth",String.valueOf(data.getMouth()));


        List list = jdbcTemplate.queryForList(sql);
        if(list.size()>0)
        {
            return LLLS_to_Class(list) ;
        }
        else
        {
            p.print_log(" 快递柜place数据库中没有数据",5);
            return list;
        }
    }


    public   List<Place_data>  LLLS_to_Class(List list)

    {
        List<Place_data> box_List= new ArrayList();
        Place_data mysql_list = new Place_data();
        for (int i=0 ; i<list.size();i++)
        {
            Object MSO = list.get(i);
            ObjectMapper objectMapper = new ObjectMapper();
            mysql_list = objectMapper.convertValue(MSO, Place_data.class);
            box_List.add(mysql_list);
        }
        return box_List;
    }



}
